#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

class Stack{
    private:
        int idx = -1;
        int stk[20];
    public:
        int pop(){
            if(idx >= 0){
                int n = stk[idx];
                idx -= 1;
                return n;
            }
            else{
                cout << "空栈" << endl;
                return -1;
            }
        }
        void push(int n){
            idx+=1;
            stk[idx] = n;
        }
        void show(){
            if(idx>=0){
            for(int i = 0 ; i <= idx ; i ++){
                cout << stk[i] << ' ';
            }
            }else{
                cout << "空栈";
            }

            cout << endl;
        }
        Stack(){}
        ~Stack(){}
};

int main() {
    Stack s;
    int in;
    while(1){
        cin >> in;
        if(in == 'p'){
            cout << s.pop();
        }
        else if(in == 'e'){
            return 0;
        }
        else{
            s.push(in);
        }
        s.show();
        
    }
    return 0;
}